/* 异步方法，执行mutations中方法 */

export default {
  // 变更语言
  changeLan({ commit }, locale) {
    localStorage.setItem('locale', locale);
    window.app.$i18n.locale = locale;
    commit('SAVE_LOCALE', locale);
  },
  // 存储token
  setToken({commit}, token) {
    localStorage.setItem('Authorization', token);
    commit('SAVE_TOKEN', token);
  },
  // 存储用户信息
  setUserInfo({commit}, userInfo) {
    localStorage.setItem('userInfo', JSON.stringify(userInfo));
    commit('SAVE_USER_INFO', userInfo);
  },
  //清除登录信息
  exit({commit}){
    localStorage.removeItem('Authorization');
    localStorage.removeItem('userInfo');
    commit('SAVE_USER_INFO', null);
    commit('SAVE_TOKEN', null);
    // window.location.href = '/'
  }
}

// this.$store.dispatch('setToken', toekn);